/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Amanda
 */
public class Help extends JPanel implements ActionListener{
    //private TransparentPanel contents = new TransparentPanel();
    protected Main parent;
    private Image[] images; //0-1 pages, 2 left arrow, 3 right arrow, 4 return, 5 ground bg
    private ImageButton leftArrow, rightArrow, returnButton;
    private JPanel pagePanel;
    private int index;
    private boolean fromStart;
    private Icon pageImage;
    private JLabel helpDisplay;

    public Help(Main parent, Image[] p){
        setLayout(new BorderLayout());
        this.parent = parent;
        images = p;
        index = 0;
        fromStart = true; //default
        pageImage = new ImageIcon(images[0]);
        leftArrow = new ImageButton(images[2], "Left", 106, 55);
        rightArrow = new ImageButton(images[3], "Right", 106, 55);
        returnButton = new ImageButton(images[4], "Return", 312, 50);
        pagePanel = new JPanel();
        pagePanel.setPreferredSize(new Dimension(519, 536));
        helpDisplay = new JLabel();
        helpDisplay.setIcon(pageImage);
        pagePanel.add(helpDisplay);
        pagePanel.setBackground(Color.BLACK);

        add(rightArrow, BorderLayout.EAST);
        add(leftArrow, BorderLayout.WEST);
        add(returnButton, BorderLayout.SOUTH);
        add(pagePanel, BorderLayout.CENTER);

        
    }

    public void init() {
        leftArrow.addActionListener(this);
        rightArrow.addActionListener(this);
        returnButton.addActionListener(this);
    }

    public void setFromStart(boolean s){
        fromStart = s;
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Return")) {

            parent.remove(this);

            if(fromStart)
                parent.add(parent.mainMenu);
            else
                parent.add(parent.pauseMenu);

            parent.validate();
            parent.repaint();
        }

        if(e.getActionCommand().equals("Left"))
        {
            if(index == 0) index = 1; //wrap around from beginning to end
            else index--;

            pageImage = new ImageIcon(images[index]);
            helpDisplay.setIcon(pageImage);
            pagePanel.repaint();
        }

        if(e.getActionCommand().equals("Right"))
        {
            if(index == 1) index = 0; //wrap around from end to beginning
            else index++;

            pageImage = new ImageIcon(images[index]);
            helpDisplay.setIcon(pageImage);
            pagePanel.repaint();
        }

    }

    @Override
    public void paintComponent(Graphics g) {
        if(images[5] != null) g.drawImage(images[5], 0, 0, null);
    }
}
